
import fetch from '../fetch';

let stringify = function (data) {
  let arr = [];
  Object.keys(data).forEach(key => {
    arr.push(key + '=' + encodeURIComponent(data[key]));
  });
  return arr.join('&');
};

const login = (account, pwd) => fetch.post('/token', {
  "grant_type": "password",
  "username": account,
  "password": pwd
}, {
  transformRequest: [function (data) {
    return stringify(data);
  }],
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  }
});
const logout = () => fetch.post('/api/v1/account/logout');

export {login};
